package facilius.controller.action.aula;

import facilius.model.ServiceLocator;
import facilius.util.TrataData;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.mentawai.core.BaseAction;

/**
 *
 * @author Graciano
 */
public class AulaReadAction extends BaseAction {

    @Override
    public String execute() throws Exception {
        String consequence = ERROR;
        try {
            Map<String, Object> criteria = new HashMap<String, Object>();
            criteria.put("professorid", session.getAttribute("userId"));

            Date dataInicio = TrataData.stringToDate(input.getString("dataInicial"));
            Date dataFim = TrataData.stringToDate(input.getString("dataFinal"));

            criteria.put("dataInicial", dataInicio);
            criteria.put("dataFinal", dataFim);

            criteria.put("professorid", session.getAttribute("userId"));

            output.setValue("pojos", ServiceLocator.getAulaService().readByCriteria(criteria));
            consequence = SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return consequence;
    }
}
